package nowcoder.hw.hj05;

import java.util.Scanner;

/**
 * 提前知晓
 * a:97
 * A:65
 * 0:48
 */
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()){
            String nextLine = in.nextLine();
            if (!nextLine.matches("0[x|X][0-9A-Fa-f]+")){
                System.out.println("无效的16进制");
            }else {
                System.out.println(convert2(nextLine));
            }


        }
    }

    private static Integer convert(String hex) {
        Integer sum = 0;
        for (int i = 2, pow = hex.length() - i - 1;
             i < hex.length();
             i++, pow = hex.length() - i - 1) {
            char c = hex.charAt(i);
            double num = 0;
            if (c >= '0' && c <= '9') num = (c - '0') * Math.pow(16, pow);
            else if (c >= 'A' && c <= 'F') num = (c - 'A' + 10) * Math.pow(16, pow);
            else num = (c - 'a' + 10) * Math.pow(16, pow);
            sum = Double.valueOf(num).intValue() + sum;
        }
        return sum;
    }

    private static Integer convert2(String hex) {
        int sum = 0;
        for (int i = 2, pow = hex.length() - i - 1;
             i < hex.length();
             i++, pow = hex.length() - i - 1) {
            int c = hex.charAt(i);
            double num = 0;
            if (c >= 'a') num = (c - 'a' + 10) * Math.pow(16, pow);
            else if (c >= 'A') num = (c - 'A' + 10) * Math.pow(16, pow);
            else num = (c-'0') * Math.pow(16, pow);
            sum = Double.valueOf(num).intValue() + sum;
        }
        return sum;
    }
}